{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5c1b7879",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'request_id': '1678938401,aeb8ce9c-56eb-4fe4-963a-7aba44cce626',\n",
       " 'time_used': 139,\n",
       " 'faces': [{'face_token': '9bb7c57b25380c2bbaa5b6b268ea5e65',\n",
       "   'face_rectangle': {'top': 120, 'left': 113, 'width': 277, 'height': 277}}],\n",
       " 'image_id': 'HkEepXy0Y3LpW2hwph7VTA==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "颜值识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('C:/Users/pc/Pictures/Camera Roll/f1e6c9cc4cc04abc8ca862b8325efb7e.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "    \"api_key\":\"_IgPsC0rO6Acs1CAhlRBJtBQa4Fg9GJC\",\n",
    "    \"api_secret\":\"XpP_-a0Qc70Pmgnq3THBDz-OgeIq2Lu-\"\n",
    "}\n",
    "access_token = '[调用鉴权接口获取的token]'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print (response.status_code)\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a59311a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
